package com.cloudeasy.api.vo;

import com.cloudeasy.api.enums.ResultCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * 结果类
 *
 * @param <T> 数据类型
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Accessors(chain = true)
public class Result<T> implements Serializable {
    /**
     * 成功标记
     */
    private Boolean flag;
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 消息
     */
    private String message;
    /**
     * {@link T}的数据
     */
    private T data;

    /**
     * 以{@link ResultCodeEnum}的构造
     *
     * @param flag           成功标记
     * @param resultCodeEnum {@link ResultCodeEnum}
     * @param data           {@link T}的数据
     */
    public Result(Boolean flag, ResultCodeEnum resultCodeEnum, T data) {
        this.flag = flag;
        this.code = resultCodeEnum.getCode();
        this.message = resultCodeEnum.getMessage();
        this.data = data;
    }
}
